<template>
  <div>
    <el-container>
      <el-header style="background-color: #687179">
        <img src="@/assets/dog.png" alt="" style="width: 40px; position: relative; top: 10px;">
        <span style="font-size: 20px; margin-left: 15px; color: white">宠物管理系统后端界面</span>
        <!--下拉菜单       -->
        <el-dropdown style="float: right;height: 60px;line-height: 60px">
      <span class="el-dropdown-link">
        <!--user是前台缓存的信息       -->
        <i class="el-icon-arrow-down el-icon--right" style="color: lightskyblue;font-size:16px">{{ user.name }}</i>
      </span>
          <el-dropdown-menu slot="dropdown">
            <!--在 el-dropdown-item里面写点击事件不生效，解决办法：加一个div标签包裹-->
            <el-dropdown-item>
              <div @click="clean()">退出登录</div>
            </el-dropdown-item>
            <!--           <el-dropdown-item>
                         <div @click="changePwd()">修改密码</div>
                       </el-dropdown-item>-->

          </el-dropdown-menu>
        </el-dropdown>
      </el-header>
    </el-container>

    <el-container>
      <el-aside style="overflow: hidden; min-height: 100vh; background-color: #545c64; width: 250px">
        <el-menu :default-active="$route.path" router
                 background-color="#545c64"
                 text-color="#fff"
                 active-text-color="#abd8f6">
          <el-menu-item index="/">
            <i class="el-icon-s-home"></i>
            <span slot="title">系统首页</span>
          </el-menu-item>
          <el-menu-item index="/admin" v-if="user.role==='ROLE_ADMIN'">
            <i class="el-icon-setting"></i>
            <span slot="title">管理员</span>
          </el-menu-item>
          <el-submenu index="2" v-if="user.role==='ROLE_ADMIN'">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>信息管理</span>
            </template>

            <el-menu-item index="/dept">部门信息管理</el-menu-item>
            <el-menu-item index="/employee">员工信息管理</el-menu-item>
            <el-menu-item index="/user">用户信息管理</el-menu-item>
            <el-menu-item index="/animals">宠物信息管理</el-menu-item>


          </el-submenu>

          <el-menu-item-group>
            <template slot="title">事务</template>
            <el-menu-item index="/audit" v-if="user.role==='ROLE_ADMIN'">领养申请</el-menu-item>
            <el-menu-item index="/completeInfo" v-if="user.role==='ROLE_DOCTOR'">完善个人信息</el-menu-item>
            <el-menu-item index="/reserve" v-if="user.role==='ROLE_DOCTOR'">预约兽医</el-menu-item>
          </el-menu-item-group>

          <el-menu-item index="charts" v-if="user.role==='ROLE_ADMIN'">
            <i class="el-icon-document"></i>
            <span slot="title" >统计</span>
          </el-menu-item>

        </el-menu>
      </el-aside>
      <el-main>
        <router-view/>

      </el-main>
    </el-container>
    <!--   <router-view/>-->
  </div>
</template>

<script>
export default {
  name: "Layout",
  data() {
    return {
      /*把前台local storage缓存的用户的字符串信息转化为json数据*/
      user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {}
    }
  },
  
  methods: {
    clean() {
      localStorage.removeItem("user");
      //跳转到login 是router
      this.$router.push("/adminLogin")
    }
  }
}
</script>

<style>
.el-menu {
  border-right: none !important;
}
</style>